home *** CD-ROM | disk | FTP | other *** search
/ Erotic Games: Memory / Erotic Games: Memory.iso / mac / air_installers / AdobeAIR.exe / setup.swf / scripts / mx / controls / HTML.as < prev    next >
Text File  |  2009-02-12  |  15KB  |  515 lines

  1. package mx.controls
  2. {
  3.    import flash.events.Event;
  4.    import flash.events.HTMLUncaughtScriptExceptionEvent;
  5.    import flash.events.MouseEvent;
  6.    import flash.html.HTMLHistoryItem;
  7.    import flash.html.HTMLHost;
  8.    import flash.html.HTMLLoader;
  9.    import flash.net.URLRequest;
  10.    import flash.system.ApplicationDomain;
  11.    import mx.controls.listClasses.BaseListData;
  12.    import mx.controls.listClasses.IDropInListItemRenderer;
  13.    import mx.controls.listClasses.IListItemRenderer;
  14.    import mx.core.ClassFactory;
  15.    import mx.core.EdgeMetrics;
  16.    import mx.core.FlexHTMLLoader;
  17.    import mx.core.IDataRenderer;
  18.    import mx.core.IFactory;
  19.    import mx.core.ScrollControlBase;
  20.    import mx.core.ScrollPolicy;
  21.    import mx.core.mx_internal;
  22.    import mx.events.FlexEvent;
  23.    import mx.managers.IFocusManagerComponent;
  24.    
  25.    use namespace mx_internal;
  26.    
  27.    public class HTML extends ScrollControlBase implements IDataRenderer, IDropInListItemRenderer, IListItemRenderer, IFocusManagerComponent
  28.    {
  29.       
  30.       private static const MAX_HTML_HEIGHT:Number = 2880;
  31.       
  32.       mx_internal static const VERSION:String = "3.0.0.0";
  33.       
  34.       private static const MAX_HTML_WIDTH:Number = 2880;
  35.        
  36.       
  37.       private var _data:Object;
  38.       
  39.       private var _userAgent:String;
  40.       
  41.       private var _htmlLoaderFactory:IFactory;
  42.       
  43.       private var _location:String;
  44.       
  45.       private var _runtimeApplicationDomain:ApplicationDomain;
  46.       
  47.       private var htmlTextChanged:Boolean = false;
  48.       
  49.       public var htmlLoader:HTMLLoader;
  50.       
  51.       private var _paintsDefaultBackground:Boolean;
  52.       
  53.       private var locationChanged:Boolean = false;
  54.       
  55.       private var htmlHostChanged:Boolean = false;
  56.       
  57.       private var _listData:BaseListData;
  58.       
  59.       private var _htmlText:String;
  60.       
  61.       private var _htmlHost:HTMLHost;
  62.       
  63.       private var paintsDefaultBackgroundChanged:Boolean = false;
  64.       
  65.       private var userAgentChanged:Boolean = false;
  66.       
  67.       private var runtimeApplicationDomainChanged:Boolean = false;
  68.       
  69.       private var textSet:Boolean;
  70.       
  71.       public function HTML()
  72.       {
  73.          _htmlLoaderFactory = new ClassFactory(FlexHTMLLoader);
  74.          super();
  75.          mx_internal::_horizontalScrollPolicy = ScrollPolicy.AUTO;
  76.          mx_internal::_verticalScrollPolicy = ScrollPolicy.AUTO;
  77.          tabEnabled = false;
  78.          tabChildren = true;
  79.       }
  80.       
  81.       public static function get pdfCapability() : int
  82.       {
  83.          return HTMLLoader.pdfCapability;
  84.       }
  85.       
  86.       public function get contentHeight() : Number
  87.       {
  88.          if(!htmlLoader)
  89.          {
  90.             return 0;
  91.          }
  92.          return htmlLoader.contentHeight;
  93.       }
  94.       
  95.       public function get userAgent() : String
  96.       {
  97.          return _userAgent;
  98.       }
  99.       
  100.       public function set userAgent(param1:String) : void
  101.       {
  102.          _userAgent = param1;
  103.          userAgentChanged = true;
  104.          invalidateProperties();
  105.       }
  106.       
  107.       public function get loaded() : Boolean
  108.       {
  109.          if(!htmlLoader || locationChanged || htmlTextChanged)
  110.          {
  111.             return false;
  112.          }
  113.          return htmlLoader.loaded;
  114.       }
  115.       
  116.       public function cancelLoad() : void
  117.       {
  118.          if(htmlLoader)
  119.          {
  120.             htmlLoader.cancelLoad();
  121.          }
  122.       }
  123.       
  124.       private function htmlLoader_htmlRenderHandler(param1:Event) : void
  125.       {
  126.          dispatchEvent(param1);
  127.          adjustScrollBars();
  128.       }
  129.       
  130.       [Bindable("htmlLoaderFactoryChanged")]
  131.       public function get htmlLoaderFactory() : IFactory
  132.       {
  133.          return _htmlLoaderFactory;
  134.       }
  135.       
  136.       public function historyForward() : void
  137.       {
  138.          if(htmlLoader)
  139.          {
  140.             htmlLoader.historyForward();
  141.          }
  142.       }
  143.       
  144.       public function set htmlLoaderFactory(param1:IFactory) : void
  145.       {
  146.          _htmlLoaderFactory = param1;
  147.          dispatchEvent(new Event("htmlLoaderFactoryChanged"));
  148.       }
  149.       
  150.       public function get historyLength() : int
  151.       {
  152.          if(!htmlLoader)
  153.          {
  154.             return 0;
  155.          }
  156.          return htmlLoader.historyLength;
  157.       }
  158.       
  159.       public function reload() : void
  160.       {
  161.          if(htmlLoader)
  162.          {
  163.             htmlLoader.reload();
  164.          }
  165.       }
  166.       
  167.       override protected function createChildren() : void
  168.       {
  169.          super.createChildren();
  170.          if(!htmlLoader)
  171.          {
  172.             htmlLoader = htmlLoaderFactory.newInstance();
  173.             htmlLoader.addEventListener(Event.HTML_DOM_INITIALIZE,htmlLoader_domInitialize);
  174.             htmlLoader.addEventListener(Event.COMPLETE,htmlLoader_completeHandler);
  175.             htmlLoader.addEventListener(Event.HTML_RENDER,htmlLoader_htmlRenderHandler);
  176.             htmlLoader.addEventListener(Event.LOCATION_CHANGE,htmlLoader_locationChangeHandler);
  177.             htmlLoader.addEventListener(Event.HTML_BOUNDS_CHANGE,htmlLoader_htmlBoundsChangeHandler);
  178.             htmlLoader.addEventListener(Event.SCROLL,htmlLoader_scrollHandler);
  179.             htmlLoader.addEventListener(HTMLUncaughtScriptExceptionEvent.UNCAUGHT_SCRIPT_EXCEPTION,htmlLoader_uncaughtScriptExceptionHandler);
  180.             addChild(htmlLoader);
  181.          }
  182.       }
  183.       
  184.       public function historyGo(param1:int) : void
  185.       {
  186.          if(htmlLoader)
  187.          {
  188.             htmlLoader.historyGo(param1);
  189.          }
  190.       }
  191.       
  192.       private function htmlLoader_domInitialize(param1:Event) : void
  193.       {
  194.          dispatchEvent(param1);
  195.       }
  196.       
  197.       private function adjustScrollBars() : void
  198.       {
  199.          setScrollBarProperties(htmlLoader.contentWidth,htmlLoader.width,htmlLoader.contentHeight,htmlLoader.height);
  200.          if(verticalScrollBar)
  201.          {
  202.             verticalScrollBar.lineScrollSize = 20;
  203.          }
  204.          if(horizontalScrollBar)
  205.          {
  206.             horizontalScrollBar.lineScrollSize = 20;
  207.          }
  208.       }
  209.       
  210.       [Bindable("dataChange")]
  211.       public function get data() : Object
  212.       {
  213.          return _data;
  214.       }
  215.       
  216.       [Bindable("locationChange")]
  217.       public function get location() : String
  218.       {
  219.          return _location;
  220.       }
  221.       
  222.       private function htmlLoader_completeHandler(param1:Event) : void
  223.       {
  224.          invalidateSize();
  225.          dispatchEvent(param1);
  226.       }
  227.       
  228.       public function set historyPosition(param1:int) : void
  229.       {
  230.          if(htmlLoader)
  231.          {
  232.             htmlLoader.historyPosition = param1;
  233.          }
  234.       }
  235.       
  236.       public function getHistoryAt(param1:int) : HTMLHistoryItem
  237.       {
  238.          if(!htmlLoader)
  239.          {
  240.             return null;
  241.          }
  242.          return htmlLoader.getHistoryAt(param1);
  243.       }
  244.       
  245.       public function get runtimeApplicationDomain() : ApplicationDomain
  246.       {
  247.          return _runtimeApplicationDomain;
  248.       }
  249.       
  250.       override protected function scrollHandler(param1:Event) : void
  251.       {
  252.          super.scrollHandler(param1);
  253.          htmlLoader.scrollH = horizontalScrollPosition;
  254.          htmlLoader.scrollV = verticalScrollPosition;
  255.       }
  256.       
  257.       public function historyBack() : void
  258.       {
  259.          if(htmlLoader)
  260.          {
  261.             htmlLoader.historyBack();
  262.          }
  263.       }
  264.       
  265.       override protected function commitProperties() : void
  266.       {
  267.          super.commitProperties();
  268.          if(htmlHostChanged)
  269.          {
  270.             htmlLoader.htmlHost = _htmlHost;
  271.             htmlHostChanged = false;
  272.          }
  273.          if(paintsDefaultBackgroundChanged)
  274.          {
  275.             htmlLoader.paintsDefaultBackground = _paintsDefaultBackground;
  276.             paintsDefaultBackgroundChanged = false;
  277.          }
  278.          if(runtimeApplicationDomainChanged)
  279.          {
  280.             htmlLoader.runtimeApplicationDomain = _runtimeApplicationDomain;
  281.             runtimeApplicationDomainChanged = false;
  282.          }
  283.          if(userAgentChanged)
  284.          {
  285.             htmlLoader.userAgent = _userAgent;
  286.             userAgentChanged = false;
  287.          }
  288.          if(locationChanged)
  289.          {
  290.             htmlLoader.load(new URLRequest(_location));
  291.             locationChanged = false;
  292.          }
  293.          if(htmlTextChanged)
  294.          {
  295.             htmlLoader.loadString(_htmlText);
  296.             htmlTextChanged = false;
  297.          }
  298.       }
  299.       
  300.       public function get contentWidth() : Number
  301.       {
  302.          if(!htmlLoader)
  303.          {
  304.             return 0;
  305.          }
  306.          return htmlLoader.contentWidth;
  307.       }
  308.       
  309.       public function get domWindow() : Object
  310.       {
  311.          if(!htmlLoader)
  312.          {
  313.             return null;
  314.          }
  315.          return htmlLoader.window;
  316.       }
  317.       
  318.       override protected function mouseWheelHandler(param1:MouseEvent) : void
  319.       {
  320.          if(param1.target != this)
  321.          {
  322.             return;
  323.          }
  324.          param1.delta *= 6;
  325.          super.mouseWheelHandler(param1);
  326.       }
  327.       
  328.       override public function set verticalScrollPosition(param1:Number) : void
  329.       {
  330.          param1 = Math.max(param1,0);
  331.          if(htmlLoader && htmlLoader.contentHeight > htmlLoader.height)
  332.          {
  333.             param1 = Math.min(param1,htmlLoader.contentHeight - htmlLoader.height);
  334.          }
  335.          super.verticalScrollPosition = param1;
  336.          if(htmlLoader)
  337.          {
  338.             htmlLoader.scrollV = param1;
  339.          }
  340.          else
  341.          {
  342.             invalidateProperties();
  343.          }
  344.       }
  345.       
  346.       public function set data(param1:Object) : void
  347.       {
  348.          var _loc2_:* = undefined;
  349.          _data = param1;
  350.          if(_listData)
  351.          {
  352.             _loc2_ = _listData.label;
  353.          }
  354.          else if(_data != null)
  355.          {
  356.             if(_data is String)
  357.             {
  358.                _loc2_ = String(_data);
  359.             }
  360.             else
  361.             {
  362.                _loc2_ = _data.toString();
  363.             }
  364.          }
  365.          if(_loc2_ !== undefined && !textSet)
  366.          {
  367.             htmlText = _loc2_;
  368.             textSet = false;
  369.          }
  370.          dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
  371.       }
  372.       
  373.       private function htmlLoader_scrollHandler(param1:Event) : void
  374.       {
  375.          horizontalScrollPosition = htmlLoader.scrollH;
  376.          verticalScrollPosition = htmlLoader.scrollV;
  377.       }
  378.       
  379.       public function get historyPosition() : int
  380.       {
  381.          if(!htmlLoader)
  382.          {
  383.             return 0;
  384.          }
  385.          return htmlLoader.historyPosition;
  386.       }
  387.       
  388.       override protected function measure() : void
  389.       {
  390.          super.measure();
  391.          var _loc1_:EdgeMetrics = viewMetrics;
  392.          _loc1_.left += getStyle("paddingLeft");
  393.          _loc1_.top += getStyle("paddingTop");
  394.          _loc1_.right += getStyle("paddingRight");
  395.          _loc1_.bottom += getStyle("paddingBottom");
  396.          measuredWidth = Math.min(htmlLoader.contentWidth + _loc1_.left + _loc1_.right,MAX_HTML_WIDTH);
  397.          measuredHeight = Math.min(htmlLoader.contentHeight + _loc1_.top + _loc1_.bottom,MAX_HTML_HEIGHT);
  398.       }
  399.       
  400.       public function set listData(param1:BaseListData) : void
  401.       {
  402.          _listData = param1;
  403.       }
  404.       
  405.       private function htmlLoader_uncaughtScriptExceptionHandler(param1:HTMLUncaughtScriptExceptionEvent) : void
  406.       {
  407.          var _loc2_:Event = param1.clone();
  408.          dispatchEvent(_loc2_);
  409.          if(_loc2_.isDefaultPrevented())
  410.          {
  411.             param1.preventDefault();
  412.          }
  413.       }
  414.       
  415.       private function htmlLoader_locationChangeHandler(param1:Event) : void
  416.       {
  417.          var _loc2_:* = _location != htmlLoader.location;
  418.          _location = htmlLoader.location;
  419.          if(_loc2_)
  420.          {
  421.             dispatchEvent(param1);
  422.          }
  423.       }
  424.       
  425.       public function set htmlHost(param1:HTMLHost) : void
  426.       {
  427.          _htmlHost = param1;
  428.          htmlHostChanged = true;
  429.          invalidateProperties();
  430.       }
  431.       
  432.       [Bindable("dataChange")]
  433.       public function get listData() : BaseListData
  434.       {
  435.          return _listData;
  436.       }
  437.       
  438.       public function set htmlText(param1:String) : void
  439.       {
  440.          _htmlText = param1;
  441.          htmlTextChanged = true;
  442.          _location = null;
  443.          locationChanged = false;
  444.          invalidateProperties();
  445.          invalidateSize();
  446.          invalidateDisplayList();
  447.          dispatchEvent(new Event("htmlTextChanged"));
  448.       }
  449.       
  450.       public function set location(param1:String) : void
  451.       {
  452.          _location = param1;
  453.          locationChanged = true;
  454.          _htmlText = null;
  455.          htmlTextChanged = false;
  456.          invalidateProperties();
  457.          invalidateSize();
  458.          invalidateDisplayList();
  459.          dispatchEvent(new Event("locationChange"));
  460.       }
  461.       
  462.       public function get htmlHost() : HTMLHost
  463.       {
  464.          return _htmlHost;
  465.       }
  466.       
  467.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  468.       {
  469.          super.updateDisplayList(param1,param2);
  470.          var _loc3_:EdgeMetrics = viewMetrics;
  471.          _loc3_.left += getStyle("paddingLeft");
  472.          _loc3_.top += getStyle("paddingTop");
  473.          _loc3_.right += getStyle("paddingRight");
  474.          _loc3_.bottom += getStyle("paddingBottom");
  475.          htmlLoader.x = _loc3_.left;
  476.          htmlLoader.y = _loc3_.top;
  477.          var _loc4_:Number = Math.max(param1 - _loc3_.left - _loc3_.right,1);
  478.          var _loc5_:Number = Math.max(param2 - _loc3_.top - _loc3_.bottom,1);
  479.          htmlLoader.width = _loc4_;
  480.          htmlLoader.height = _loc5_;
  481.       }
  482.       
  483.       [Bindable("htmlTextChanged")]
  484.       public function get htmlText() : String
  485.       {
  486.          return _htmlText;
  487.       }
  488.       
  489.       private function htmlLoader_htmlBoundsChangeHandler(param1:Event) : void
  490.       {
  491.          invalidateSize();
  492.          adjustScrollBars();
  493.       }
  494.       
  495.       public function get paintsDefaultBackground() : Boolean
  496.       {
  497.          return _paintsDefaultBackground;
  498.       }
  499.       
  500.       public function set paintsDefaultBackground(param1:Boolean) : void
  501.       {
  502.          _paintsDefaultBackground = param1;
  503.          paintsDefaultBackgroundChanged = true;
  504.          invalidateProperties();
  505.       }
  506.       
  507.       public function set runtimeApplicationDomain(param1:ApplicationDomain) : void
  508.       {
  509.          _runtimeApplicationDomain = param1;
  510.          runtimeApplicationDomainChanged = true;
  511.          invalidateProperties();
  512.       }
  513.    }
  514. }
  515.